package com.crois.barrier.web.support;

import com.zhimydou.zlp.constants.TokenConstants;
import org.springframework.http.server.reactive.ServerHttpRequest;

import java.util.List;

/**
 * @author Hou Ze Yu
 * @description
 * @date 2020/1/29
 */
public class TokenUtil {
    public static String getToken (ServerHttpRequest request){
        List<String> headers = request.getHeaders().get(TokenConstants.AUTH_HEADER);
        String   token =null;
        if (headers!=null&&headers.get(0)!=null&&headers.get(0)!=""){
            if (headers.get(0).contains("%20")){
                token= headers.get(0).split(TokenConstants.ENCODE_TOKEN_PREFIX)[1];
            }else {
                token= headers.get(0).split(TokenConstants.TOKEN_PREFIX)[1];
            }
        }
        return token ;
    }
}
